package io.renren.roomManager.service.impl;

import cn.lingyueblog.common.utils.PageUtils;
import cn.lingyueblog.common.utils.Query;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.roomManager.dao.BuildingsDao;
import io.renren.roomManager.entity.BuildingsEntity;
import io.renren.roomManager.service.BuildingsService;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.Map;


@Service("buildingsService")
public class BuildingsServiceImpl extends ServiceImpl<BuildingsDao, BuildingsEntity> implements BuildingsService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<BuildingsEntity> wrapper = new QueryWrapper<BuildingsEntity>();
        String key = (String) params.get("key");

        if(!key.isEmpty()){
            wrapper.like("name",key);
        }

        IPage<BuildingsEntity> page = this.page(
                new Query<BuildingsEntity>().getPage(params),
                wrapper
        );

        return new PageUtils(page);
    }

    @Override
    public void buildingSave(BuildingsEntity buildings) {
        buildings.setCreatedat(new Date());
        buildings.setUpdatedat(new Date());
        buildings.setDeletedat(null);
        save(buildings);
    }

}